package com.example.james.uicustomviews;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null){
            actionBar.hide();
        }
//        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
        FruitAdapter fruitAdapter = new FruitAdapter(this, R.layout.fruit_item, initFruits());
        ListView listView = findViewById(R.id.list_view);
//        listView.setAdapter(arrayAdapter);
        listView.setAdapter(fruitAdapter);
        listView.setOnItemClickListener(fruitAdapter);
    }

    private List<Fruit> initFruits(){
        List<Fruit> fruitList = new ArrayList<>();
        for (int i = 0; i < 3; i++){
            Fruit apple = new Fruit("apple", R.drawable.apple_pic);
            Fruit banana = new Fruit("banana", R.drawable.banana_pic);
            Fruit cherry = new Fruit("cherry", R.drawable.cherry_pic);
            Fruit grape = new Fruit("grape", R.drawable.grape_pic);
            Fruit mango = new Fruit("mango", R.drawable.mango_pic);
            Fruit orange = new Fruit("orange", R.drawable.orange_pic);
            Fruit pear = new Fruit("pear", R.drawable.pear_pic);
            fruitList.add(apple);
            fruitList.add(banana);
            fruitList.add(cherry);
            fruitList.add(grape);
            fruitList.add(mango);
            fruitList.add(orange);
            fruitList.add(pear);
        }
        return fruitList;
    }


    private String[] data = {"Apple", "Banana", "Orange", "Watermelon", "Pear", "Grape", "Pineapple", "Apple", "Banana", "Orange", "Watermelon", "Pear", "Grape", "Pineapple"};
}
